package com.example.origin.demo.demo;

import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@RequestMapping("VolatileDemo")
@RestController
public class VolatileDemo {

	private volatile Integer num = 0;


	@SneakyThrows
	@GetMapping("test")
	public void test(){
		new Thread(() -> {
            while (num!=10){

			}
			System.out.println("thread end");
        }).start();


		new Thread(() -> {
			for (int i = 0; i < Integer.MAX_VALUE; i++) {
				num++;
			}
			System.out.println("thread2 end");
			num =0;
		}).start();

		TimeUnit.SECONDS.sleep(10);
		System.out.println("end");


	}


}
